﻿using System.Web.UI;
namespace SiteUnity.Frame.Common.UITools
{
    public enum ContainerType 
    {
        div,
        p,
        span,
        ul,        
        ol,
        li,
        h1,
        h2,
        h3,
        h4,
        h5,
        h6,
        table,
        tr,
        th,
        thead,
        tfoot,
        center,
        code
    }

    public class Container : System.Web.UI.WebControls.Panel
    {
        public override string ID { get; set; }
        public ContainerType Tag { get; set; }
        public string InnerText { get; set; }

        public Container() 
        {
            Tag = ContainerType.div;

            if (string.IsNullOrEmpty(ID))
                ID ="su_container_" + new System.Random().Next();
        }

        public override void RenderControl(System.Web.UI.HtmlTextWriter writer)
        {
            writer.AddAttribute("id", this.ID);
            writer.AddAttribute("style", this.Style.Value);
            writer.AddAttribute("class", this.CssClass);
            writer.RenderBeginTag(Tag.ToString());

            if (!string.IsNullOrEmpty(InnerText))
                writer.Write(InnerText);

            //base.RenderControl(writer);

            foreach (Control control in this.Controls)
                control.RenderControl(writer);
            
            writer.RenderEndTag();
        }
    }
}
